import {dateFormat, getHttpPath} from '../../js/my-utils'
import {_ANIME_PATH_, _TOTAL_PATH_} from '../../js/my-core'

export const getAnimeRefresh = (_this) => {
  _this.$axios({
    method: 'get',
    url: '/api/anime/get_refresh'
  })
    .then((res) => {
      if (res.data.code === 200) {
        _this.animeLists = []
        let id = 0
        for (let items of res.data.data) {
          // console.log(items)
          if (items === []) {
            _this.animeLists.push([])
            continue
          }
          let its = []
          for (let item of items) {
            let it = {id: id, refreshed: 1, refreshTime: '18:00', href: '#', cover: null, name: 'NULL', collected: 0, no: 0}
            it.refreshed = item.status
            it.refreshTime = dateFormat('HH:MM', new Date(item.refreshTime))
            it.href = item.status === 1 ? _ANIME_PATH_ + item.animeVideoId : _TOTAL_PATH_[0] + item.animeId
            it.cover = getHttpPath(item.cover)
            it.name = item.name
            it.no = item.no
            its.push(it)
            id++
          }
          _this.animeLists.push(its)
        }
        _this.animeList = _this.animeLists[3]
        _this.$nextTick(function () {
          // div高度同步
          let height = _this.$('article.sidebar-icon:eq(0)').css('height')
          _this.$('div.sidebar-title').css('height', height)
        })
        //   let items = []
        //   for (let j = 0; j < 5; j++) {
        //     let item = {id: i * 8 + j, refreshed: 1, refreshTime: '18:00', href: '#', cover: null, name: 'NULL', collected: 0, no: 12}
        //     if ((i === 3 && j > 1) || i > 3) {
        //       item.refreshed = 0
        //     }
        //     items.push(item)
        //   }
        //   this.animeLists.push(items)
        // }
        // this.animeList = this.animeLists[3]
      }
    })
    .catch((error) => {
      console.log(error)
    })
}
